package com.demo;

import cn.hutool.core.io.FileUtil;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mifei
 * @create 2021-04-12 17:29
 **/
public class IoUtis {
	/**
	 * 将文件转换成byte数组
	 * @param file 目标文件
	 * @return
	 */
	public static byte[] fileToByte(File file) {
		byte[] bytes = null;
		try {
			FileInputStream fis = new FileInputStream(file);
			ByteArrayOutputStream bos = new ByteArrayOutputStream();
			byte[] b = new byte[1024];
			int n;
			while ((n = fis.read(b)) != -1) {
				bos.write(b, 0, n);
			}
			fis.close();
			bos.close();
			bytes = bos.toByteArray();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bytes;
	}

	public static void main(String[] args) throws Exception {
		File file = new File("D:/存储过程参数.docx");
		new IoUtis().fileToByte(file);
	}
}
